package com.cow.horse.controller;

import com.cow.horse.entity.HealthRecord;
import com.cow.horse.service.HealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/healthrecord")
public class HealthController {
    @Autowired
    private HealthService healthService;

    @GetMapping("/{username}")
    public ResponseEntity<HealthRecord> getHealthRecord(@PathVariable String username) {
        HealthRecord record = healthService.findByUsername(username);
        if (record == null) {
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(record);
    }

    @PostMapping("/update")
    public ResponseEntity<HealthRecord> updateHealthRecord(@RequestBody HealthRecord record) {
        HealthRecord updatedRecord = healthService.updateHealthRecord(record);
        return ResponseEntity.ok().body(updatedRecord);
    }
}